package com.example.deliveryapplication

import android.content.Context
import android.content.Intent
import android.graphics.Color
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.LinearLayout
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.example.deliveryapplication.entity.*

class DetailsAdapter(private val context: Context, private val mList: List<Details>, private val listener:CallBack,private val whereFrom:Int) :
    BaseRecyclerViewAdapter(context, mList) {
    override fun createViewHolder(parent: ViewGroup): RecyclerView.ViewHolder {
        val view = LayoutInflater.from(context).inflate(R.layout.item_details_list, parent, false)
        return MyViewHolder(view)
    }

    override fun handlerData(holder: RecyclerView.ViewHolder, position: Int) {
        if (holder is MyViewHolder) {
            val data = mList[position]
            holder.dataTitle.text=data.title
            holder.dataContent.text=data.content
            holder.remarkTV.text=data.remark
            holder.dataCU.text=data.cu
            holder.deleteTV.setOnClickListener {
                listener.onItemDelete(position,data)
            }
            if(whereFrom==1){
                holder.deleteTV.visibility=View.GONE
            }else{
                holder.deleteTV.visibility=View.VISIBLE
            }
        }
    }

    inner class MyViewHolder(view: View) : RecyclerView.ViewHolder(view) {
        val dataTitle: TextView = view.findViewById(R.id.dataTitle)
        val dataContent: TextView = view.findViewById(R.id.dataContent)
        val remarkTV:TextView=view.findViewById(R.id.remarkTV)
        val dataCU:TextView=view.findViewById(R.id.dataCU)
        val deleteTV:TextView=view.findViewById(R.id.deleteTV)
    }

    interface CallBack {
        fun onItemDelete(position: Int, data: Details)
        fun onItemCopy(position: Int, data: Details)
    }

}